package frame.util.shiro;

import frame.base.BaseConstant;
import frame.system.to.User;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.springframework.beans.factory.annotation.Autowired;

public class UserListener implements SessionListener {

    @Autowired
    private ShiroJdbc shiroJdbc;

    @Override
    public void onStart(Session session) {
        //System.out.println("会话创建：" + session.getId());
    }

    @Override
    public void onStop(Session session) {
        //System.out.println("会话退出：" + session.getId());
        User user = (User) session.getAttribute(BaseConstant.SYSTEM_LOGIN);
        shiroJdbc.logout(user.getUsername());
    }

    @Override
    public void onExpiration(Session session) {
        //System.out.println("会话过期：" + session.getId());
    }
}
